/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            downShopHouseManageInfo: {
                inoutOrders: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shId: '',
                curOrder: {},
                states: [],
                conditions: {
                    personName: '',
                    orderId: '',
                    orderType: '20000',
                    state: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('inout_order', "state", function (_data) {
                $that.downShopHouseManageInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('downShopHouseManage', 'listInoutOrder', function (_param) {
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('downShopHouseManage', 'notifyAuditInfo', function (_param) {
                $that._auditOrderState(_param);
            })
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listInoutOrder(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listInoutOrder: function (_page, _rows) {
                $that.downShopHouseManageInfo.conditions.page = _page;
                $that.downShopHouseManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.downShopHouseManageInfo.conditions
                };
                param.params.orderId = param.params.orderId.trim();
                param.params.personName = param.params.personName.trim();
                //发送get请求
                vc.http.apiGet('/inoutOrder/queryInoutOrder',
                    param,
                    function (json, res) {
                        var _downShopHouseManageInfo = JSON.parse(json);
                        $that.downShopHouseManageInfo.total = _downShopHouseManageInfo.total;
                        $that.downShopHouseManageInfo.records = _downShopHouseManageInfo.records;
                        $that.downShopHouseManageInfo.inoutOrders = _downShopHouseManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.downShopHouseManageInfo.records,
                            dataCount: $that.downShopHouseManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopHouseModal: function () {
                vc.jumpToPage('/#/pages/goods/downShopHouseOutManage');
            },
            //查询
            _queryShopHouseMethod: function () {
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopHouseMethod: function () {
                $that.downShopHouseManageInfo.conditions.orderId = "";
                $that.downShopHouseManageInfo.conditions.personName = "";
                $that.downShopHouseManageInfo.conditions.state = "";
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _deleteUpShopHouse(_inoutOrder) {
                vc.emit('deleteInoutOrder', 'openDeleteShopHouseModal', _inoutOrder)
            },
            _moreCondition: function () {
                if ($that.downShopHouseManageInfo.moreCondition) {
                    $that.downShopHouseManageInfo.moreCondition = false;
                } else {
                    $that.downShopHouseManageInfo.moreCondition = true;
                }
            },
            _openAuditModal: function (_order) {
                $that.downShopHouseManageInfo.curOrder = _order;
                vc.emit('audit', 'openAuditModal', {});
            },
            _auditOrderState: function (_auditInfo) {
                let _order = $that.downShopHouseManageInfo.curOrder;
                _order.state = _auditInfo.state;
                _order.stateRemark = _auditInfo.remark;
                _order.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/inoutOrder/auditInoutOrder',
                    JSON.stringify(_order),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        if (res.status == 200) {
                            //关闭model
                            $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
                            return;
                        }
                        vc.toast(json);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _toDetail: function (_inoutOrder) {
                vc.jumpToPage('/#/pages/goods/upShopHouseDetail?orderId=' + _inoutOrder.orderId);
            }
        }
    });
})(window.vc);
